home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15491 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. From: jamie@pro-net.co.uk (James Dickson)
  2. Newsgroups: comp.lang.c
  3. Subject: Re: Pointer to Functions and Calls thereof??
  4. Date: Fri, 19 Apr 1996 10:07:20 GMT
  5. Message-ID: <31776500.1903078@news.globalnet.co.uk>
  6. References: <Dq01Ft.Dqn@latcs1.lat.oz.au>
  7. X-Newsreader: Forte Agent .99d/32.182
  8. NNTP-Posting-Host: client8114.globalnet.co.uk
  9. Path: news.globalnet.co.uk!
  10.  
  11. On Wed, 17 Apr 1996 09:09:28 GMT, woelkerl@lion.cs.latrobe.edu.au
  12. (Eric Woelkerling) wrote:
  13.  
  14. >    Hi!    Can anybody fill me in as to how to get a pointer to a function
  15. >and then use this to do the call??  I have a situation where a particular function
  16. >will be selected from a set of functions and used throughout my entire code,
  17. >but the function selected will depend on the runtime selection by thge user..
  18. >
  19. >so far.. I have got as far as..
  20. >
  21. >
  22. >    void    func1(void){naughty bits}
  23. >    void    func2(void){naughty bits}
  24. >
  25. >    void    main(void)
  26. >    {    void    *a[1];
  27. >
  28. >        a[1]=func1;
  29. >        a[2]=func2;
  30. >
  31. >        (*a[1])();
  32. >    }
  33. >
  34. >    Is there something obvious I am missing here??  I am on a PC and using 
  35. >borland c++ compiler... 
  36. >
  37. >    If you can help,  please mail me directly     Thanks!
  38. >
  39. >    Eric Woelkerling
  40. >    woelkerl@lion.lat.oz.au
  41. >
  42.  
  43. Eric,
  44.  
  45. I think your declaration for 'a' should be:
  46.  
  47. void (*a[2])();
  48.  
  49.  
  50. Try it and let me know.
  51.  
  52.  
  53. James Dickson.
  54.